<?php

class Transport_TruckController extends Base_Controller_Action
{

    public function indexAction()
    {
        //fetch data
        $dbTable = new Table_Truck();
        Zend_Paginator::setCache(Zend_Registry::get('Zend_Cache'));
        $this->view->paginator = Zend_Paginator::factory(
                $dbTable->select()
                    #->where('`gid` = ?', $group->gid)
                    ->order(array('pubdate DESC'))
            );

        //check page
        if (is_numeric($this->_getParam('page'))) {
            $this->view->paginator->setCurrentPageNumber($this->_getParam('page'));
        }
        
        $dbTable = new Table_District();
        $districtArray = $dbTable->view();
        foreach ($districtArray as $district) {
            $districts[$district->aid] = $district->name;
        }
        
        $this->view->districts = $districts;
        $this->_helper->layout->setLayout('browse');
    }
    
    public function createAction()
    {
        //create form
        $this->form = new Form_Truck_Create();
        
        try {
            $this->create('truck');
        }
        catch (Base_Exception $e) {
            return $this->_forward('clewbox','post','default',array(
                'message' => $e->getMessage()
            ));
        }
    }
    
    public function modifyAction()
    {
        //create form
        $this->form = new Form_Truck_Modify();
        
        try {
            $this->modify('truck');
        }
        catch (Base_Exception $e) {
            return $this->_forward('clewbox','post','default',array(
                'message' => $e->getMessage()
            ));
        }
    }
    
    public function deleteAction()
    {
        $this->form = new Form_Truck_Delete();
        
        //drop post
        try {
            $this->delete('truck');
        }
        catch (Base_Exception $e) {
            return $this->_forward('clewbox','post','default',array(
                'message' => $e->getMessage()
            ));
        }
    }
}